$(function() {
        initTable();

        setTimeout(poll, 5000);
});

let timer = null

function poll() {
        if (timer) {
             clearInterval(timer)
        }

        timer = setInterval("search()", parseInt($("#pollingTime").val()) * 1000)
}

/**
* 初始化表格
*/
function initTable() {
$('#mainTracelogTable').DataTable({
language: Language,
columns: [
        {
        "data": "traceId",
        "title": "主链路ID"
        },
        {
                "data": "serviceName",
                "title": "服务名称"
        },
        {
        "data": "name",
        "title": "任务名称"
        },
        {
        "data": "resultFlag",
        "title": "结果",
        "render": function (data, type, row, meta) {
                if (data == "0") {
                        return "成功"
                } else if (data == "1") {
                        return "失败"
                } else {
                        return "部分成功"
                }
        }
        },
        {
                "data": "startTime",
                "title": "开始时间"
        },
        {
                "data": "endTime",
                "title": "结束时间"
        },
        {
                "data": "elapsedTime",
                "title": "耗时(ms)"
        },
        {
                "data": "null",
                "title": "操作",
                "render": function (data, type, row, meta) {
                        return `<button class="btn btn-primary" style="margin-right: 5px" data-toggle="modal" data-target="#detailModal" onClick="detailShow(this)">详情</button>`
                }
        }
],
dom: 'rt<"bottom"ilp><"clear">',
destroy : true,
searching: false,
processing : true,
serverSide: true,
bSort: false,
autoWidth: false,
lengthMenu: [10],


ajax: {
type: "post",
contentType: "application/json",
url: searchUrl,
dataFilter: dataFilterFunc,
data: function(param) {
        let json = $("#mainTracelogForm").serializeObject();
        json.pageNum = param.start / 10 + 1;
        json.pageSize = param.length;
        return JSON.stringify(json)
},
error: errorFunc
}
});
}

/**
* 查询
*/
function search() {
reloadTable('mainTracelogTable');
}

function detailShow(_this) {
        let tr = $(_this).parent().parent();
        let row = getRowDataTable('mainTracelogTable', tr);
        loadForm("mainDetailForm", row)
}






